const mongoose = require("./db");

const UserSchema = new mongoose.Schema(
  {
    user: String,
    password: String,
    name: String,
    img: String,
    guanzhu: {
      type: Number,
      default: 0
    },
    fensi: {
      type: Number,
      default: 0
    },
    beizan: {
      type: Number,
      default: 0
    },
    score: {
      type: Number,
      default: 0
    },
    uni: {
      type: Number,
      default: 0
    },
    price: {
      type: Number,
      default: 0
    },
    guanzhuId: {
      type: Array,
      default: []
    },
  },
  {
    versionKey: false
  }
);
const OrderSchema = new mongoose.Schema(
  {
    title: String,
    img: String,
    price: Number,
    buyers: String,
    seller: String,
    content: String,
    wuliu: String,
    type: String,
    paystatus: {
      type: Boolean,
      default: false,
    }
  },
  {
    versionKey: false,
  }
);
const ListSchema = new mongoose.Schema(
  {
    name: String,
    img: String,
    price: Number,
    content: String,
  },
  {
    versionKey: false,
  }
);
const ChatSchema = new mongoose.Schema(
  {
    content: String,
    sendId: {
      type: mongoose.Types.ObjectId,
      ref: 'User'
    },
    acceptId: {
      type: mongoose.Types.ObjectId,
      ref: 'User'
    },
    time: Date
  },
  {
    versionKey: false
  }
)

const homegoodSchema = new mongoose.Schema(
  {
    title: String,
    img: String,
    type: String,
    num: Number,
    status:{
      type:Boolean,
      default:false
    }
  },
  {
    versionKey: false,
  }
);

const RecommentSchema = new mongoose.Schema(
  {
    head: String,
    name: String,
    fans: Number,
    content: String,
    img1: String,
    img2: String,
    img3: String,
    read: String,
    like: String,
    comment: String
  }
)

const TopicSchema = new mongoose.Schema(
  {
    title: String,
    hot: Number
  }
)

// 宝库列表
const Goldmine = new mongoose.Schema({
  title: String,
  follow: Number,
  exp: Number
})
// 发布帖子
const tie = new mongoose.Schema({
  title: String,
  img: String,
  connect: String,
  Fid: String
})



const HomegoodModel = mongoose.model('homegood', homegoodSchema, 'homegood')
const UserModel = mongoose.model("User", UserSchema, "User");
const ChatModel = mongoose.model('Chat', ChatSchema, 'Chat')
const ListModel = mongoose.model("List", ListSchema, "List");
const OrderModel = mongoose.model("Order", OrderSchema, "Order");
const RecommentModel = mongoose.model('Recomment', RecommentSchema, 'Recomment')
const TopicModel = mongoose.model("Topic", TopicSchema, "Topic")
const GoldModel = mongoose.model("gold", Goldmine, "gold")
const TieModel = mongoose.model("tie", tie, "tie")

module.exports = {
  UserModel, ChatModel, HomegoodModel, OrderModel, ListModel, RecommentModel, TopicModel, TieModel, GoldModel
};
